package com.sky.controller.user;


import com.sky.context.BaseContext;
import com.sky.entity.Story;
import com.sky.result.Result;
import com.sky.dto.StroyDTO;
import com.sky.service.StroyService;
import com.sky.vo.StoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/stories")
@Slf4j
@Api(tags = "故事相关接口")
public class StroyController {




    @Autowired
    private StroyService stroyService;

    /**
     * 生成故事接口
     * @param storyDTO
     * @return
     */
    @PostMapping("")
    @ApiOperation("生成故事接口")
    public Result<StoryVo> getStory(@RequestBody StroyDTO storyDTO) {
        StoryVo storyVo=stroyService.getStroy(storyDTO);
        return Result.success(storyVo);
    }


    /**
     * 查询当前用户的故事
     * @return
     */
    @GetMapping("")
    @ApiOperation("查询当前用户的故事")
    public Result<List<Story>> getStoryList() {
        Long userId= BaseContext.getCurrentId();
        List<Story> list=stroyService.getByUserId(userId);
        return Result.success(list);
    }

    /**
     * 根据id删除故事
     * @param id
     * @return
     */
    @DeleteMapping("")
    @ApiOperation("根据id删除故事")
    public Result deleteStory(Long id) {
        stroyService.delete(id);
        return Result.success();
    }
}
